 # 字典: 一系列键值对    键: 值
 # 同 类class
alien_0 = {'color': 'green', 'points': 5}

print(alien_0['color'])

new_point = alien_0['points']
print(f"You just earned {new_point} points.")

alien_0 = {} # {}定义空的字典

alien_0['x_position'] = 0
alien_0['y_position'] = 25 # 直接指定键值对就能添加到字典内
# dictionary['key'] 访问字典中的某元素

print(alien_0)

alien_0['speed'] = 'medium'

print(f"Original position: {alien_0['x_position']}")

if alien_0['speed'] == 'slow':
    x_increment = 1
elif alien_0['speed'] == 'medium':
    x_increment = 2
elif alien_0['speed'] == 'fast':
    x_increment = 3

alien_0['x_position'] += x_increment
print(f"New position: {alien_0['x_position']}")

alien_0 = {'color': 'green', 'points': 5}
del alien_0['color'] # 删除键值对，只需要给出键即可
print(alien_0)

# 使用get()避免键值不存在的错误 dictionary.get('ask_value', 'error_back') error_back可选，若不填，返回None
speed_value = alien_0.get('speed', 'no speed value')
print(speed_value)